<template>
  <h1>循环指令</h1>
  <ul style="list-style: none">
<!-- item从1开始，每执行一次，item的值+1，一直到数字n   -->
<!-- v-for的效果：执行五次，生成5个li，里面是数字1，2，3，4，5   -->
    <li v-for="item in 5">{{item}}</li>
  </ul>

  <ul style="list-style: none">
    <li v-for="item in productArr">{{item}}</li>
  </ul>
  <table border="1" cellspacing="0" align="center">
      <tr>
        <th>编号</th>
        <th>种类</th>
        <th>价格</th>
        <th>数量</th>
        <th>操作</th>
      </tr>
      <tr v-for="(item, index) in productArr">
        <td>{{index+1}}</td>
        <td>{{item.title}}</td>
        <td>{{item.price}}</td>
        <td>{{item.num}}</td>
        <td><button @click="del(index)">删除</button></td>
      </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";
const productArr = ref([
    {title:'苹果',price:10,num:10},
    {title:'香蕉',price:20,num:20},
    {title:'橘子',price:30,num:30},
    {title:'西瓜',price:40,num:40},
    {title:'桃子',price:50,num:50},
    {title:'梨子',price:60,num:60},
  ]);
const del = (index) =>{
  if (confirm('确定删除吗？')){
    productArr.value.splice(index,1);
  }

}
</script>

<style scoped>

</style>